<?php
/****************************************************************************

	COPYRIGHT(C) WWW.MAXSI.DK, MAXSI SOFTWARE, SORTIE 2009
	ALL RIGHTS RESERVED

	Maxsi Distribution ContentServer/ Branch
	Scripts running a Maxsi Distribution Compatible Content Server.	
	
	public_frontpage.php
	The frontpage for a maxsi compatible content server running the public/
	branch of the Maxsi Distribution Server System.

****************************************************************************/

if ( md_IsOutputHTML() )
{

?>

<p>

<b class="text_big"><?php echo $_GET['product']; ?></b><br />

This is the information stored about <?php echo $_GET['product']; ?> on this Content Server.<br /><br />

</p>

<table>
<?php
}

mdc_SendVariableTextFull("Product",$_GET['product']);

if ( $md_db )
{

	$slot	=	md_sql("SELECT * FROM ".md_GetDatabaseName('products')." WHERE name = '".md_SlashGlobalVar($_GET['product'])."'");
	
	if ( $md_sql_total[$slot] )
	{
		mdc_SendVariableTextFull("Supported",'Yes');
		
		mdc_SendVariableTextFull("ContentType",$md_sql_row[$slot]['ContentType']);
		
		if ( strcasecmp($md_sql_row[$slot]['ContentType'],"Steam/SourceMod") == 0 ||
		     strcasecmp($md_sql_row[$slot]['ContentType'],"Steam/SourceMapPack") == 0 )
		{		
			mdc_SendVariableTextFull("Requires Game Folder",$md_sql_row[$slot]['RequiresGameFolder']);
			mdc_SendVariableTextFull("Map Pack For",$md_sql_row[$slot]['MapPackFor']);
		}
		
		$archives	=	md_sql('SELECT arch.name as name FROM `'.md_GetDatabaseName('contentarchive_rel').'` rel, `'.md_GetDatabaseName('contentarchive').'` arch, `'.md_GetDatabaseName('products').'` product WHERE product.name = "'.md_SlashGlobalVar($_GET['product']).'" AND product.id = rel.product AND arch.id = rel.archive');		

		if ( $md_sql_total[$archives] )
		{
			for ( $i = 0; $i < $md_sql_total[$archives]; $i++)
			{
				mdc_SendVariableTextFull("Download",$md_sql_row[$archives]['name']);
				md_sql_next($archives);				
			}
		}
		
		md_clearslot($archives);	
		
		function	md_OutputTextFile($FileName,$VariableName)
		{
			if ( file_exists('addons/masterserver/Licenses/'.$FileName) == false ) { return false; }
		
			$MD_Client_License	=	file_get_contents('addons/masterserver/Licenses/'.$FileName);
			
			// Make sure line endings are outputted as \r\n
			$HasSlashR			=	stripos($MD_Client_License,"\r");
			$HasSlashN			=	stripos($MD_Client_License,"\n");
			
			if ( $HasSlashR !== $HasSlashN )
			{
				if ( $HasSlashR)
				{
					$MD_Client_License		=	str_replace("\r","\r\n",$MD_Client_License);
				}				
				else
				{
					$MD_Client_License		=	str_replace("\n","\r\n",$MD_Client_License);
				}
			}
				
			if ( md_IsOutputHTML() )
			{
				$MD_Client_License	=	str_replace("\r\n","<br />",md_html2text($MD_Client_License));
			}
			
			mdc_SendVariableTextFull($VariableName,$MD_Client_License);
		}
		
		md_OutputTextFile($_GET['product']."-Welcome.txt","Product-Welcome");
		md_OutputTextFile($_GET['product']."-License.txt","Product-License");
		md_OutputTextFile("MD-License.txt","MD-License");		
	}
	else
	{
		mdc_SendVariableTextFull("Supported",'No');
	}
	
	md_clearslot($slot);
}
else
{
	mdc_SendVariableTextFull("Supported",'No');
}

if ( md_IsOutputHTML() )
{
?></table><?php
}

?>